package com.lingz.manager.modules.wuxue.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lingz.manager.modules.wuxue.dao.OpeEntInfoDao;
import com.lingz.manager.modules.wuxue.entity.KeyAreaInfo;
import com.lingz.manager.modules.wuxue.mapper.OpeEntInfoMapper;
import com.lingz.manager.modules.wuxue.entity.OpeEntInfo;
import com.lingz.manager.modules.wuxue.service.OpeEntInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
@Transactional
public class OpeEntInfoServiceImpl implements OpeEntInfoService {
    @Autowired
    OpeEntInfoDao opeEntInfoDao;

    @Autowired
    OpeEntInfoMapper opeEntInfoMapper;

    @Override
    public OpeEntInfoDao getRepository() {
        return opeEntInfoDao;
    }


    @Override
    public List<OpeEntInfo> findListOpeEntInfo(OpeEntInfo opeEntInfo) {
        LambdaQueryWrapper<OpeEntInfo> wrapper = Wrappers.lambdaQuery(OpeEntInfo.class);
        List<OpeEntInfo> list = opeEntInfoMapper.selectList(wrapper);
        return list;
    }

    @Override
    public OpeEntInfo findOpeEntInfoById(int id) {
         return opeEntInfoMapper.selectById(id);
    }

    public List<OpeEntInfo> findOpeEntInfoByType(String entityType) {
        LambdaQueryWrapper<OpeEntInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OpeEntInfo::getEntityType, entityType);
        wrapper.orderByAsc(OpeEntInfo::getId);
        return opeEntInfoMapper.selectList(wrapper);
    }

    @Override
    public Integer findOpeEntInfoNumByType(String entityType, String cityName, String townName, String villageName) {
        LambdaQueryWrapper<OpeEntInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OpeEntInfo::getEntityType, entityType);
        if (StringUtils.isNotBlank(cityName)) {
            wrapper.eq(OpeEntInfo::getCityName, cityName);
        }
        if (StringUtils.isNotBlank(townName)) {
            wrapper.eq(OpeEntInfo::getTownName, townName);
        }
        if (StringUtils.isNotBlank(villageName)) {
            wrapper.eq(OpeEntInfo::getVillageName, villageName);
        }
        return opeEntInfoMapper.selectCount(wrapper);
    }

    @Override
    public Integer findOpeEntInfoNumByInd(String industry, String cityName, String townName, String villageName) {
        LambdaQueryWrapper<OpeEntInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OpeEntInfo::getIndustryCategory, industry);
        if (StringUtils.isNotBlank(cityName)) {
            wrapper.eq(OpeEntInfo::getCityName, cityName);
        }
        if (StringUtils.isNotBlank(townName)) {
            wrapper.eq(OpeEntInfo::getTownName, townName);
        }
        if (StringUtils.isNotBlank(villageName)) {
            wrapper.eq(OpeEntInfo::getVillageName, villageName);
        }
        return opeEntInfoMapper.selectCount(wrapper);
    }

    @Override
    public Integer findOpeEntInfoNumByBus(String business, String cityName, String townName, String villageName) {
        LambdaQueryWrapper<OpeEntInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OpeEntInfo::getBusinessSector, business);
        if (StringUtils.isNotBlank(cityName)) {
            wrapper.eq(OpeEntInfo::getCityName, cityName);
        }
        if (StringUtils.isNotBlank(townName)) {
            wrapper.eq(OpeEntInfo::getTownName, townName);
        }
        if (StringUtils.isNotBlank(villageName)) {
            wrapper.eq(OpeEntInfo::getVillageName, villageName);
        }
        return opeEntInfoMapper.selectCount(wrapper);
    }
}
